interface HTMLElementPlus extends HTMLElement {
  mozRequestFullScreen: Function,
  webkitRequestFullScreen: Function,
  msRequestFullscreen: Function,
}

interface DocumentPlus extends Document {
  mozCancelFullScreen: Function,
  webkitCancelFullScreen: Function,
  msExitFullscreen: Function,
}

export default function () {
  function fullScreen() {
    var explorer = window.navigator.userAgent.toLowerCase();
    if (explorer.indexOf("chrome") > 0) {
      //webkit
      if (
        document.body.scrollHeight === window.screen.height &&
        document.body.scrollWidth === window.screen.width
      ) {
        exitFullscreen();
      } else {
        enterFullscreen();
      }
    } else {
      //IE 9+  fireFox
      if (
        window.outerHeight === window.screen.height &&
        window.outerWidth === window.screen.width
      ) {
        exitFullscreen();
      } else {
        enterFullscreen();
      }
    }
    function enterFullscreen() {
      var docElm = document.documentElement as HTMLElementPlus;
      //W3C
      if (docElm.requestFullscreen) {
        docElm.requestFullscreen();
      }
      //FireFox
      else if (docElm.mozRequestFullScreen) {
        docElm.mozRequestFullScreen();
      }
      //Chrome等
      else if (docElm.webkitRequestFullScreen) {
        docElm.webkitRequestFullScreen();
      }
      //IE11
      else if (docElm.msRequestFullscreen) {
        docElm.msRequestFullscreen();
      }
    }
    function exitFullscreen() {
      const _document_ = document as DocumentPlus
      //W3C
      if (_document_.exitFullscreen) {
        _document_.exitFullscreen();
      }
      //FireFox
      else if (_document_.mozCancelFullScreen) {
        _document_.mozCancelFullScreen();
      }
      //Chrome等
      else if (_document_.webkitCancelFullScreen) {
        _document_.webkitCancelFullScreen();
      }
      //IE11
      else if (_document_.msExitFullscreen) {
        _document_.msExitFullscreen();
      }
    }
  }
  return {
    fullScreen
  }
}